package com.hhh.petadopt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hhh.petadopt.pojo.LmessageVo;
import com.hhh.petadopt.pojo.LostMessage;
import com.hhh.petadopt.service.AdminMesageService;
import com.hhh.petadopt.utils.JsonUtils;
import com.hhh.petadopt.utils.Page;

/**
 * 留言
 * @author 杜镇声声
 *
 */
@Controller
public class AdminMessageController {
	
	@Autowired
	private AdminMesageService adminMesageService;
	
	@RequestMapping("/adminMessage/lsotMessage")
	public String selectPage(LmessageVo Vo,Model model) {
		//执行查询
		Page<LostMessage> page = adminMesageService.selectPage(Vo);
		//将数据保存到域中
		model.addAttribute("page", page);
		//保存总条数和搜索信息回显
		model.addAttribute("total", page.getTotal());
		model.addAttribute("lldate", Vo.getLldate());
		return "admin/Lmessage";
	}
	
	//留言信息回显
	@RequestMapping(value="/adminMessage/showMessage")
	@ResponseBody
	public String selectMessage(String id) {
		//执行查询
		LostMessage selectMessageById = adminMesageService.selectMessageById(id);
		return JsonUtils.objectToJson(selectMessageById);
	}
	
	//禁言
	@RequestMapping(value="/adminMessage/updateShow")
	@ResponseBody
	public String updateMessage(LostMessage lms) {
		//执行禁言操作
		adminMesageService.updateShow(lms);
		String str = "ok";
		return JsonUtils.objectToJson(str);
	}
	//解除禁言
	@RequestMapping(value="/adminMessage/cancelsay")
	@ResponseBody
	public String cancelSay(String id) {
		
		//执行操作
		adminMesageService.cancalKeepSay(id);
		String str = "ok";
		return JsonUtils.objectToJson(str);
	}
	
	//删除留言
	@RequestMapping(value="/adminMessage/delmessage")
	@ResponseBody
	public String delMessage(String id) {
		
		adminMesageService.delMessageById(id);
		
		String str = "成功";
		return JsonUtils.objectToJson(str);
	}
	
	//批量删除
	@RequestMapping(value="/adminMessage/delAllMessage")
	@ResponseBody
	public String delAllMessages(Integer[] ids) {
		
		adminMesageService.delAllMessages(ids);
		String str = "成功";
		return JsonUtils.objectToJson(str);
	}

}
